<template>
  <div id="source">
    <div class="source-title">
      <h2>源码</h2>
    </div>
    <div class="source-content">
      <el-row id="artList" type="flex" justify="space-around" v-for="item of sourceList" :key="item.id">
        <el-col>
          <el-row class="art-item">
            <el-card shadow="hover">
              <h5>
                <router-link :to="'/source/' + item.id" tag="span" class="art-title">{{ item.title }}</router-link>
              </h5>
              <el-row class="art-info d-flex align-items-center justify-content-start">
                <div class="art-time">
                  <i class="el-icon-time"/>：{{ item.createTime }}
                </div>
              </el-row>
              <el-row class="art-body">
                <div class="side-img hidden-sm-and-down">
                  <router-link :to="'/source/' + item.id"><img class="art-banner" :src="item.avatar"></router-link>
                </div>
                <div class="side-abstract">
                  <div class="art-abstract">
                    {{ replaceHtml(item.content) }}
                  </div>
                  <div class="art-more">
                    <router-link :to="'/source/' + item.id" tag="span">
                      <el-button plain>阅读全文</el-button>
                    </router-link>
                    <div class="view"><i class="el-icon-view"/>{{ item.quantity }}</div>
                  </div>
                </div>
              </el-row>
              <i class="iconfont icon-top01 star"></i>
            </el-card>
          </el-row>
        </el-col>
      </el-row>
      <div class="block pagination">
        <el-pagination background layout="prev, pager, next" :current-page="currentPage" :page-size="pageSize"
                       :total="total" @current-change="handleCurrentChange"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>

import {listSource} from "@/api";
import {replaceHtml} from "@/views/article";

export default {
  name: "source",
  data() {
    return {
      sourceList: [],
      pageSize: 10,
      currentPage: 1,
      total: 0
    }
  },
  created() {
    this.listSource()
  },
  methods: {
    listSource() {
      listSource({pageNum: this.currentPage, pageSize: this.pageSize}).then(res => {
        this.sourceList = res.data.results;
        this.currentPage = res.data.pageNum;
        this.total = res.data.total;
      })
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.listSource();
    },
    // html只保留文本
    replaceHtml(val) {
      return replaceHtml(val);
    }
  }
}
</script>

<style scoped lang="less">
#source {
  margin: 20px;
  background-color: #fff;
}

.source-title {
  height: 70px;
  line-height: 70px;
  margin-left: 20px;
}

.source-content {
  width: 90%;
  margin: 0 20px 20px 20px;
}

.art-item {
  margin-bottom: 20px;
  position: relative;
}

.art-title {
  border-left: 3px solid #F56C6C;
  padding-left: 5px;
  cursor: pointer;
}

.art-title:hover {
  padding-left: 10px;
  color: #409EFF;
}

.art-time {
  margin-right: 20px;
}

.art-body {
  display: flex;
  padding: 10px 0;
}

.side-img {
  height: 150px;
  width: 270px;
  overflow: hidden;
  margin-right: 10px;
}

.art-item .star {
  font-size: 20px;
  width: 60px;
  height: 60px;
  position: absolute;
  color: orangered;
  top: 2%;
  right: 0;
}

img.art-banner {
  width: 100%;
  height: 100%;
  transition: all 0.6s;
}

img.art-banner:hover {
  transform: scale(1.4);
}

.side-abstract {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.art-abstract {
  flex: 1;
  color: #aaa;
}

.art-more {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.art-more .view {
  color: #aaa;
}

.art-info {
  margin-top: 20px;
  display: flex;
}

h5 {
  font-size: 18px;
}

.pagination {
  padding: 20px 0;
}
</style>
